package com.kiloai.digcust.mvp.view.activity;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.kiloai.base.basemvp.MVPBaseActivity;
import com.kiloai.base.utils.LogUtil;
import com.kiloai.base.utils.PermissionUtils;
import com.kiloai.digcust.R;
import com.kiloai.digcust.mvp.presenter.RecordingPresenter;
import com.kiloai.recorder.listener.RecordStreamListener;
import com.kiloai.recorder.recorder.AudioRecorder;

import butterknife.OnClick;

/**
 * Created by david on 2018/8/17.
 */

public class RecordingActivity extends MVPBaseActivity<RecordingActivity,RecordingPresenter> {

    private RecordingPresenter presenter;

    @Override
    protected RecordingPresenter createPresenter() {
        if (presenter == null){
            presenter = new RecordingPresenter();
        }
        return presenter;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    private void startRecord() {
        PermissionUtils.getInstance(this).requestPermissions(100, new PermissionUtils.OnPermissionRequestListener() {
            @Override
            public void onPermissionGranted() {
                AudioRecorder.getInstance().createDefaultAudio(System.currentTimeMillis() + "_test");
                AudioRecorder.getInstance().startRecord(new RecordStreamListener() {
                    @Override
                    public void recordOfByte(byte[] data, int begin, int end) {
                        LogUtil.e(TAG, "begin:" + begin);
                        LogUtil.e(TAG, "end:" + end);
                    }
                });
            }

            @Override
            public void onPermissionDenied() {

            }
        }, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }

    private void endRecord(){
        AudioRecorder.getInstance().stopRecord();
    }
}
